package com.laizhenghua.hotel.controller;

import java.util.Arrays;
import java.util.Map;

import com.laizhenghua.hotel.utils.PageUtils;
import com.laizhenghua.hotel.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.laizhenghua.hotel.entity.AdsEntity;
import com.laizhenghua.hotel.service.AdsService;

/**
 * @author laizhenghua
 * @email 3299447929@qq.com
 * @date 2021-03-11 15:23:23
 */
@RestController
@RequestMapping("hotel/ads")
public class AdsController {
    @Autowired
    private AdsService adsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = adsService.queryPage(params);
        // System.out.println(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		AdsEntity ads = adsService.getById(id);

        return R.ok().put("ads", ads);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AdsEntity ads){
		adsService.save(ads);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AdsEntity ads){
		adsService.updateById(ads);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		adsService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
